
package com.market.dao;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.market.bean.Lineitem;
import com.market.bean.Orders;
import com.market.dao.hibernate.GenericDaoHibernate;

/**
 * Data access object (DAO) for domain model class Lineitem.
 * 
 * @see com.market.bean.Lineitem
 * @author MyEclipse - Hibernate Tools
 */
public class LineitemDAO extends GenericDaoHibernate<Lineitem, Long> implements ILineitemDAO
{

    public LineitemDAO(Class<Lineitem> persistentClass)
    {
        super(persistentClass);
        // TODO Auto-generated constructor stub
    }
    public LineitemDAO()
    {
        super();
    }
    
    private static final Logger log = LoggerFactory.getLogger(LineitemDAO.class);

    // property constants
    public static final String AMOUNT = "amount";

    public static final String PRICE = "price";

    protected void initDao()
    {
        // do nothing
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.market.dao.ILineitemDAO#findById(java.lang.Long)
     */
    public Lineitem findById(java.lang.Long id)
    {
        log.debug("getting Lineitem instance with id: " + id);
        try
        {
            Lineitem instance = (Lineitem)getHibernateTemplate().get("com.market.bean.Lineitem", id);
            return instance;
        }
        catch (RuntimeException re)
        {
            log.error("get failed", re);
            throw re;
        }
    }

    private List findByProperty(String propertyName, Object value)
    {
        log.debug("finding Lineitem instance with property: " + propertyName + ", value: " + value);
        try
        {
            String queryString = "from Lineitem as model where model." + propertyName + "= ?";
            return getHibernateTemplate().find(queryString, value);
        }
        catch (RuntimeException re)
        {
            log.error("find by property name failed", re);
            throw re;
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.market.dao.ILineitemDAO#findByOrders(com.market.bean.Orders)
     */
    public List findByOrders(Orders o)
    {
        return findByProperty("orders", o);
    }
}
